unit RelGraf_ProdFaturado2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Series, TeEngine, TeeProcs, Chart, DBChart, StdCtrls, ExtCtrls, Buttons,teeprevi;

type
  TFrmRelGraf_ProdFaturado2 = class(TForm)
    Panel2: TPanel;
    bimprimir: TBitBtn;
    bfechar: TBitBtn;
    Panel1: TPanel;
    Btn_Maior: TSpeedButton;
    Btn_menor: TSpeedButton;
    Btn_normal: TSpeedButton;
    Ed_estilo: TRadioGroup;
    Ed_legenda: TRadioGroup;
    DbGrafico: TDBChart;
    Series1: TBarSeries;
    DBGrafico2: TDBChart;
    Series2: TPieSeries;
    procedure Btn_MaiorClick(Sender: TObject);
    procedure Btn_menorClick(Sender: TObject);
    procedure Btn_normalClick(Sender: TObject);
    procedure Ed_estiloClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure bimprimirClick(Sender: TObject);
    procedure Ed_estiloExit(Sender: TObject);
    procedure Ed_legendaClick(Sender: TObject);
    procedure bfecharClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmRelGraf_ProdFaturado2: TFrmRelGraf_ProdFaturado2;
  tot_Vendas : double;
  Ordem      : integer;

implementation


uses Biblio, RelGraf_ProdFaturado;
{$R *.DFM}

procedure TFrmRelGraf_ProdFaturado2.Btn_MaiorClick(Sender: TObject);
begin
  DbGrafico.ZoomPercent(110);
end;

procedure TFrmRelGraf_ProdFaturado2.Btn_menorClick(Sender: TObject);
begin
  DbGrafico.ZoomPercent(90);
end;

procedure TFrmRelGraf_ProdFaturado2.Btn_normalClick(Sender: TObject);
begin
  DbGrafico.UndoZoom;
end;

procedure TFrmRelGraf_ProdFaturado2.Ed_estiloClick(Sender: TObject);
begin
  if Ed_estilo.ItemIndex = 0 then begin
    Btn_Maior.Visible := true;
    Btn_menor.Visible := true;
    Btn_normal.Visible := true;
    DbGrafico2.Align   := alNone;
    DbGrafico.Align    := alBottom;
    DbGrafico.visible  := true;
    DbGrafico2.visible := false;
  end else begin
    Btn_Maior.Visible := false;
    Btn_menor.Visible := false;
    Btn_normal.Visible := false;
    DbGrafico.Align    := alNone;
    DbGrafico2.Align   := alBottom;
    DbGrafico.visible  := false;
    DbGrafico2.visible := true;
  end;
end;

procedure TFrmRelGraf_ProdFaturado2.FormActivate(Sender: TObject);
begin
  if Ordem = 0 then begin
    Series2.PieValues.ValueSource:='valor_unit';
    Series1.YValues.ValueSource  :='valor_unit';
  end else begin
    Series2.PieValues.ValueSource:='qtde';
    Series1.YValues.ValueSource  :='qtde';
  end;
  DbGrafico.LeftAxis.Title.Caption :='Total de Vendas: R$'+Format_Valor(tot_Vendas);
  DbGrafico2.Foot.Visible := true;
  DbGrafico2.Foot.Text.Clear;
  DbGrafico2.Foot.Text.Add('Total de Vendas: R$'+Format_Valor(tot_Vendas));
  Ed_estiloClick(sender);
  Ed_legendaClick(sender);
end;

procedure TFrmRelGraf_ProdFaturado2.bimprimirClick(Sender: TObject);
begin
  if Ed_estilo.ItemIndex = 0 then
    ChartPreview(FrmRelGraf_ProdFaturado2,DbGrafico)
  else
    ChartPreview(FrmRelGraf_ProdFaturado2,DbGrafico2);
  bfecharClick(Sender);
end;

procedure TFrmRelGraf_ProdFaturado2.Ed_estiloExit(Sender: TObject);
begin
  bimprimir.Enabled := true;
  bimprimir.SetFocus;
end;

procedure TFrmRelGraf_ProdFaturado2.Ed_legendaClick(Sender: TObject);
begin
  if Ed_legenda.ItemIndex = 0 then begin
    DbGrafico.Legend.Alignment := laright;
    DbGrafico2.Legend.Alignment := laright;
  end else begin
    DbGrafico.Legend.Alignment := laTop;
    DbGrafico2.Legend.Alignment := laTop;
  end;
end;

procedure TFrmRelGraf_ProdFaturado2.bfecharClick(Sender: TObject);
begin
  close;
end;

end.
